package org.nokatag.Connection;

import java.sql.Connection;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.Concest;
import org.nokatag.system.ServletNokaContext;
import org.nokatag.system.SpringObjectFactory;

public class SpringHibernateSessionFactory extends SpringObjectFactory implements DBConnectionInterface{

	public Connection getConnection() {
		//ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletNokaContext.getServletContext());
		SessionFactory sessionFactory = (SessionFactory)bulidBean(Concest.DB_SPRING_SESSION_FACTORY);
		Session hsession=sessionFactory.openSession();
		ServletNokaContext.setHibernateSession(hsession);
		return hsession.connection();//获取connection
	}

	public void closeConnection(Connection con) {
		try{
			if(null!=con){
				try{con.close();}catch(Exception se){BugInfoWrint.Print(se);}
				ServletNokaContext.getHibernateSession().close();
			}
		}catch(Exception se){
			
		}
	}

}
